package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "护理项目相关接口")
@RequestMapping("/nursing_project")
public class NursingProjectController  {
    @Autowired
    public NursingProjectService nursingProjectServer;

    /**
     * 分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation("条件查询")
    public ResponseResult<PageResponse<NursingProjectVo>> pageQuery(
            @ApiParam(name = "name",value = "护理项目名称") String name,
            @ApiParam(name = "pageNum",value = "页码")
            @RequestParam(required = false ,defaultValue = "1") Integer pageNum,
            @ApiParam(name = "pageSize",value = "条数")
            @RequestParam(required = false ,defaultValue = "10") Integer pageSize,
            @ApiParam(name = "status",value = "状态（0：禁用，1：启用）")  Integer status
    ) {
        PageResponse<NursingProjectVo>pageResponse=  nursingProjectServer.pageQuery(name,pageNum,pageSize,status);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 新增
     * @param dto
     * @return
     */
    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult  addNursingProject(
            @ApiParam(value = "护理项目dto对象",required = true )
            @RequestBody NursingProjectDto dto){
        nursingProjectServer.addNursingProject(dto);
        return ResponseResult.success();
    }
    /**
     * 回显
     */
    @ApiOperation("根据id查询")
    @GetMapping("{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        NursingProjectVo vo=nursingProjectServer.getById(id);
        return ResponseResult.success(vo);
    }
    /**
     * 修改
     */
    @ApiOperation("修改护理项目")
    @PutMapping
    public ResponseResult updateNursingProject(
            @ApiParam(value = "护理项目dto对象",required = true )
            @RequestBody NursingProjectDto dto){
        nursingProjectServer.updateNursingProject(dto);
        return ResponseResult.success();
    }
    /**
     * 删除
     */
    @ApiOperation("根据id删除")
    @DeleteMapping("{id}")
    public ResponseResult deleteNursingProject(@PathVariable Long id){
        nursingProjectServer.deleteNursingProject(id);
        return ResponseResult.success();
    }
    /**
     * 禁用
     */
    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult statusNursingProject(@PathVariable Long id ,
                                               @PathVariable Integer status){
       nursingProjectServer.statusNursingProject(id,status);
        return ResponseResult.success();
    }

    /**
     * 列出所有护理项目
     */
    @ApiOperation("列出所有护理项目")
    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>>getAllNursingProject(){
        List<NursingProjectVo>list=  nursingProjectServer.getAllNursingProject();
        return ResponseResult.success(list);
    }
}
